﻿Imports System.Math
Imports MySql.Data.MySqlClient

Module func
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As IntPtr, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
    Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr

    Public Sub waitstandby(ByVal Interval) '延时
        Dim __time As DateTime = DateTime.Now
        Dim __Span As Int64 = Interval * 10000   '因为时间是以100纳秒为单位。
        While (DateTime.Now.Ticks - __time.Ticks < __Span)
            '  Application.DoEvents()
        End While
    End Sub

    Public Sub wait(ByVal Interval) '延时，可以做其他线程
        Dim __time As DateTime = DateTime.Now
        Dim __Span As Int64 = Interval * 10000   '因为时间是以100纳秒为单位。
        While (DateTime.Now.Ticks - __time.Ticks < __Span)
            Application.DoEvents()
        End While
    End Sub

    Public Function TwoPoint(ByVal x1, ByVal y1, ByVal x3, ByVal y3) As returnXY
        '函数用法：20个输入参数，前六个是拍照点PMA工具传过来的偏移量。
        '所有参与的数据必须为同一坐标系。

        Dim returnxy As returnXY
        Dim L31, L31_, L41, L51, L61, L71, temp_returnX1, temp_returnY1, temp_returnR1 As Double
        Dim L81, L91, LA1, LB1, LC1, LD1, LE1, LF1 As Double
        Dim A41, A51, A61, A71, A81, A91, AA1, AB1, AC1, AD1, AE1, AF1 As Double

        L31 = Sqrt(Pow((XY.X03 - XY.X01), 2) + Pow((XY.y03 - XY.y01), 2))

        L31_ = Sqrt(Pow((XY.X03 + x3 - XY.X01 - x1), 2) + Pow((XY.y03 + y3 - XY.y01 - y1), 2))

        If Abs(L31 - L31_) > 0.5 Or x1 > 100 Then
            returnxy.X1 = 900
            returnxy.Y1 = 900
            returnxy.X2 = 900
            returnxy.Y2 = 900
            returnxy.X3 = 900
            returnxy.Y3 = 900
            returnxy.X4 = 900
            returnxy.Y4 = 900
            returnxy.X5 = 900
            returnxy.Y5 = 900
            returnxy.X6 = 900
            returnxy.Y6 = 900
            returnxy.X7 = 900
            returnxy.Y7 = 900
            returnxy.X8 = 900
            returnxy.Y8 = 900
            returnxy.X9 = 900
            returnxy.Y9 = 900
            returnxy.X10 = 900
            returnxy.Y10 = 900
            returnxy.X11 = 900
            returnxy.Y11 = 900
            returnxy.X12 = 900
            returnxy.Y12 = 900
            GoTo over
        End If
        L41 = Sqrt(Pow((XY.X04 - XY.X01), 2) + Pow((XY.y04 - XY.y01), 2))

        L51 = Sqrt(Pow((XY.X05 - XY.X01), 2) + Pow((XY.y05 - XY.y01), 2))

        L61 = Sqrt(Pow((XY.X06 - XY.X01), 2) + Pow((XY.y06 - XY.y01), 2))

        L71 = Sqrt(Pow((XY.X07 - XY.X01), 2) + Pow((XY.y07 - XY.y01), 2))

        L81 = Sqrt(Pow((XY.X08 - XY.X01), 2) + Pow((XY.y08 - XY.y01), 2))

        L91 = Sqrt(Pow((XY.X09 - XY.X01), 2) + Pow((XY.y09 - XY.y01), 2))

        LA1 = Sqrt(Pow((XY.X0A - XY.X01), 2) + Pow((XY.y0A - XY.y01), 2))

        LB1 = Sqrt(Pow((XY.X0B - XY.X01), 2) + Pow((XY.y0B - XY.y01), 2))

        LC1 = Sqrt(Pow((XY.X0C - XY.X01), 2) + Pow((XY.y0C - XY.y01), 2))

        LD1 = Sqrt(Pow((XY.X0D - XY.X01), 2) + Pow((XY.y0D - XY.y01), 2))

        temp_returnR1 = Atan((XY.y01 - XY.y03) / (XY.X01 - XY.X03)) - Atan(((y1 + XY.y01) - (y3 + XY.y03)) / ((x1 + XY.X01) - (x3 + XY.X03)))

        If temp_returnR1 > 1 Then
            temp_returnR1 -= Acos(-1)
        End If
        If temp_returnR1 < -1 Then
            temp_returnR1 += Acos(-1)
        End If

        A41 = Atan((XY.y04 - XY.y01) / (XY.X04 - XY.X01)) - temp_returnR1

        A51 = Atan((XY.y05 - XY.y01) / (XY.X05 - XY.X01)) - temp_returnR1

        A61 = Atan((XY.y06 - XY.y01) / (XY.X06 - XY.X01)) - temp_returnR1

        A71 = Atan((XY.y07 - XY.y01) / (XY.X07 - XY.X01)) - temp_returnR1

        A81 = Atan((XY.y08 - XY.y01) / (XY.X08 - XY.X01)) - temp_returnR1

        A91 = Atan((XY.y09 - XY.y01) / (XY.X09 - XY.X01)) - temp_returnR1

        AA1 = Atan((XY.y0A - XY.y01) / (XY.X0A - XY.X01)) - temp_returnR1

        AB1 = Atan((XY.y0B - XY.y01) / (XY.X0B - XY.X01)) - temp_returnR1

        AC1 = Atan((XY.y0C - XY.y01) / (XY.X0C - XY.X01)) - temp_returnR1

        AD1 = Atan((XY.y0D - XY.y01) / (XY.X0D - XY.X01)) - temp_returnR1

        If XY.X01 - XY.X04 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X04 + L41 * Cos(A41)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X04 - L41 * Cos(A41)
        End If

        If XY.X01 - XY.X04 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y04 + L41 * Sin(A41)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y04 - L41 * Sin(A41)
        End If

        returnxy.X1 = temp_returnX1
        returnxy.Y1 = temp_returnY1

        If XY.X01 - XY.X05 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X05 + L51 * Cos(A51)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X05 - L51 * Cos(A51)
        End If

        If XY.X01 - XY.X05 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y05 + L51 * Sin(A51)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y05 - L51 * Sin(A51)
        End If

        returnxy.X2 = temp_returnX1
        returnxy.Y2 = temp_returnY1

        If XY.X01 - XY.X06 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X06 + L61 * Cos(A61)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X06 - L61 * Cos(A61)
        End If

        If XY.X01 - XY.X06 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y06 + L61 * Sin(A61)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y06 - L61 * Sin(A61)
        End If

        returnxy.X3 = temp_returnX1
        returnxy.Y3 = temp_returnY1

        If XY.X01 - XY.X07 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X07 + L71 * Cos(A71)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X07 - L71 * Cos(A71)
        End If

        If XY.X01 - XY.X07 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y07 + L71 * Sin(A71)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y07 - L71 * Sin(A71)
        End If

        returnxy.X4 = temp_returnX1
        returnxy.Y4 = temp_returnY1

        If XY.X01 - XY.X08 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X08 + L81 * Cos(A81)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X08 - L81 * Cos(A81)
        End If

        If XY.X01 - XY.X08 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y08 + L81 * Sin(A81)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y08 - L81 * Sin(A81)
        End If

        returnxy.X5 = temp_returnX1
        returnxy.Y5 = temp_returnY1

        If XY.X01 - XY.X09 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X09 + L91 * Cos(A91)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X09 - L91 * Cos(A91)
        End If

        If XY.X01 - XY.X09 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y09 + L91 * Sin(A91)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y09 - L91 * Sin(A91)
        End If

        returnxy.X6 = temp_returnX1
        returnxy.Y6 = temp_returnY1

        If XY.X01 - XY.X0A < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X0A + LA1 * Cos(AA1)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X0A - LA1 * Cos(AA1)
        End If

        If XY.X01 - XY.X0A < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y0A + LA1 * Sin(AA1)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y0A - LA1 * Sin(AA1)
        End If

        returnxy.X7 = temp_returnX1
        returnxy.Y7 = temp_returnY1

        If XY.X01 - XY.X0B < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X0B + LB1 * Cos(AB1)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X0B - LB1 * Cos(AB1)
        End If

        If XY.X01 - XY.X0B < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y0B + LB1 * Sin(AB1)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y0B - LB1 * Sin(AB1)
        End If

        returnxy.X8 = temp_returnX1
        returnxy.Y8 = temp_returnY1

        If XY.X01 - XY.X0C < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X0C + LC1 * Cos(AC1)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X0C - LC1 * Cos(AC1)
        End If

        If XY.X01 - XY.X0C < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y0C + LC1 * Sin(AC1)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y0C - LC1 * Sin(AC1)
        End If

        returnxy.X9 = temp_returnX1
        returnxy.Y9 = temp_returnY1

        If XY.X01 - XY.X0D < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X0D + LD1 * Cos(AD1)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X0D - LD1 * Cos(AD1)
        End If

        If XY.X01 - XY.X0D < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y0D + LD1 * Sin(AD1)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y0D - LD1 * Sin(AD1)
        End If

        returnxy.X10 = temp_returnX1
        returnxy.Y10 = temp_returnY1
over:
        Return returnxy
    End Function

    Public Function TwoPoint_12(ByVal x1, ByVal y1, ByVal x3, ByVal y3) As returnXY
        '函数用法：20个输入参数，前六个是拍照点PMA工具传过来的偏移量。
        '所有参与的数据必须为同一坐标系。

        Dim returnxy As returnXY
        Dim L31, L31_, L41, L51, L61, L71, temp_returnX1, temp_returnY1, temp_returnR1 As Double
        Dim L81, L91, LA1, LB1, LC1, LD1, LE1, LF1 As Double
        Dim A41, A51, A61, A71, A81, A91, AA1, AB1, AC1, AD1, AE1, AF1 As Double

        L31 = Sqrt(Pow((XY.X03 - XY.X01), 2) + Pow((XY.y03 - XY.y01), 2))

        L31_ = Sqrt(Pow((XY.X03 + x3 - XY.X01 - x1), 2) + Pow((XY.y03 + y3 - XY.y01 - y1), 2))

        If Abs(L31 - L31_) > 0.5 Or x1 > 100 Then
            returnxy.X1 = 900
            returnxy.Y1 = 900
            returnxy.X2 = 900
            returnxy.Y2 = 900
            returnxy.X3 = 900
            returnxy.Y3 = 900
            returnxy.X4 = 900
            returnxy.Y4 = 900
            returnxy.X5 = 900
            returnxy.Y5 = 900
            returnxy.X6 = 900
            returnxy.Y6 = 900
            returnxy.X7 = 900
            returnxy.Y7 = 900
            returnxy.X8 = 900
            returnxy.Y8 = 900
            returnxy.X9 = 900
            returnxy.Y9 = 900
            returnxy.X10 = 900
            returnxy.Y10 = 900
            returnxy.X11 = 900
            returnxy.Y11 = 900
            returnxy.X12 = 900
            returnxy.Y12 = 900
            GoTo over
        End If
        L41 = Sqrt(Pow((XY.X04 - XY.X01), 2) + Pow((XY.y04 - XY.y01), 2))

        L51 = Sqrt(Pow((XY.X05 - XY.X01), 2) + Pow((XY.y05 - XY.y01), 2))

        L61 = Sqrt(Pow((XY.X06 - XY.X01), 2) + Pow((XY.y06 - XY.y01), 2))

        L71 = Sqrt(Pow((XY.X07 - XY.X01), 2) + Pow((XY.y07 - XY.y01), 2))

        L81 = Sqrt(Pow((XY.X08 - XY.X01), 2) + Pow((XY.y08 - XY.y01), 2))

        L91 = Sqrt(Pow((XY.X09 - XY.X01), 2) + Pow((XY.y09 - XY.y01), 2))

        LA1 = Sqrt(Pow((XY.X0A - XY.X01), 2) + Pow((XY.y0A - XY.y01), 2))

        LB1 = Sqrt(Pow((XY.X0B - XY.X01), 2) + Pow((XY.y0B - XY.y01), 2))

        LC1 = Sqrt(Pow((XY.X0C - XY.X01), 2) + Pow((XY.y0C - XY.y01), 2))

        LD1 = Sqrt(Pow((XY.X0D - XY.X01), 2) + Pow((XY.y0D - XY.y01), 2))

        LE1 = Sqrt(Pow((XY.X0E - XY.X01), 2) + Pow((XY.y0E - XY.y01), 2))

        LF1 = Sqrt(Pow((XY.X0F - XY.X01), 2) + Pow((XY.y0F - XY.y01), 2))

        temp_returnR1 = Atan((XY.y01 - XY.y03) / (XY.X01 - XY.X03)) - Atan(((y1 + XY.y01) - (y3 + XY.y03)) / ((x1 + XY.X01) - (x3 + XY.X03)))

        If temp_returnR1 > 1 Then
            temp_returnR1 -= Acos(-1)
        End If
        If temp_returnR1 < -1 Then
            temp_returnR1 += Acos(-1)
        End If

        A41 = Atan((XY.y04 - XY.y01) / (XY.X04 - XY.X01)) - temp_returnR1

        A51 = Atan((XY.y05 - XY.y01) / (XY.X05 - XY.X01)) - temp_returnR1

        A61 = Atan((XY.y06 - XY.y01) / (XY.X06 - XY.X01)) - temp_returnR1

        A71 = Atan((XY.y07 - XY.y01) / (XY.X07 - XY.X01)) - temp_returnR1

        A81 = Atan((XY.y08 - XY.y01) / (XY.X08 - XY.X01)) - temp_returnR1

        A91 = Atan((XY.y09 - XY.y01) / (XY.X09 - XY.X01)) - temp_returnR1

        AA1 = Atan((XY.y0A - XY.y01) / (XY.X0A - XY.X01)) - temp_returnR1

        AB1 = Atan((XY.y0B - XY.y01) / (XY.X0B - XY.X01)) - temp_returnR1

        AC1 = Atan((XY.y0C - XY.y01) / (XY.X0C - XY.X01)) - temp_returnR1

        AD1 = Atan((XY.y0D - XY.y01) / (XY.X0D - XY.X01)) - temp_returnR1

        AE1 = Atan((XY.y0E - XY.y01) / (XY.X0E - XY.X01)) - temp_returnR1

        AF1 = Atan((XY.y0F - XY.y01) / (XY.X0F - XY.X01)) - temp_returnR1

        If XY.X01 - XY.X04 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X04 + L41 * Cos(A41)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X04 - L41 * Cos(A41)
        End If

        If XY.X01 - XY.X04 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y04 + L41 * Sin(A41)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y04 - L41 * Sin(A41)
        End If

        returnxy.X1 = temp_returnX1
        returnxy.Y1 = temp_returnY1

        If XY.X01 - XY.X05 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X05 + L51 * Cos(A51)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X05 - L51 * Cos(A51)
        End If

        If XY.X01 - XY.X05 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y05 + L51 * Sin(A51)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y05 - L51 * Sin(A51)
        End If

        returnxy.X2 = temp_returnX1
        returnxy.Y2 = temp_returnY1

        If XY.X01 - XY.X06 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X06 + L61 * Cos(A61)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X06 - L61 * Cos(A61)
        End If

        If XY.X01 - XY.X06 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y06 + L61 * Sin(A61)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y06 - L61 * Sin(A61)
        End If

        returnxy.X3 = temp_returnX1
        returnxy.Y3 = temp_returnY1

        If XY.X01 - XY.X07 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X07 + L71 * Cos(A71)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X07 - L71 * Cos(A71)
        End If

        If XY.X01 - XY.X07 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y07 + L71 * Sin(A71)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y07 - L71 * Sin(A71)
        End If

        returnxy.X4 = temp_returnX1
        returnxy.Y4 = temp_returnY1

        If XY.X01 - XY.X08 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X08 + L81 * Cos(A81)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X08 - L81 * Cos(A81)
        End If

        If XY.X01 - XY.X08 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y08 + L81 * Sin(A81)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y08 - L81 * Sin(A81)
        End If

        returnxy.X5 = temp_returnX1
        returnxy.Y5 = temp_returnY1

        If XY.X01 - XY.X09 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X09 + L91 * Cos(A91)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X09 - L91 * Cos(A91)
        End If

        If XY.X01 - XY.X09 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y09 + L91 * Sin(A91)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y09 - L91 * Sin(A91)
        End If

        returnxy.X6 = temp_returnX1
        returnxy.Y6 = temp_returnY1

        If XY.X01 - XY.X0A < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X0A + LA1 * Cos(AA1)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X0A - LA1 * Cos(AA1)
        End If

        If XY.X01 - XY.X0A < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y0A + LA1 * Sin(AA1)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y0A - LA1 * Sin(AA1)
        End If

        returnxy.X7 = temp_returnX1
        returnxy.Y7 = temp_returnY1

        If XY.X01 - XY.X0B < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X0B + LB1 * Cos(AB1)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X0B - LB1 * Cos(AB1)
        End If

        If XY.X01 - XY.X0B < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y0B + LB1 * Sin(AB1)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y0B - LB1 * Sin(AB1)
        End If

        returnxy.X8 = temp_returnX1
        returnxy.Y8 = temp_returnY1

        If XY.X01 - XY.X0C < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X0C + LC1 * Cos(AC1)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X0C - LC1 * Cos(AC1)
        End If

        If XY.X01 - XY.X0C < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y0C + LC1 * Sin(AC1)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y0C - LC1 * Sin(AC1)
        End If

        returnxy.X9 = temp_returnX1
        returnxy.Y9 = temp_returnY1

        If XY.X01 - XY.X0D < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X0D + LD1 * Cos(AD1)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X0D - LD1 * Cos(AD1)
        End If

        If XY.X01 - XY.X0D < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y0D + LD1 * Sin(AD1)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y0D - LD1 * Sin(AD1)
        End If

        returnxy.X10 = temp_returnX1
        returnxy.Y10 = temp_returnY1

        If XY.X01 - XY.X0E < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X0E + LE1 * Cos(AE1)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X0E - LE1 * Cos(AE1)
        End If

        If XY.X01 - XY.X0E < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y0E + LE1 * Sin(AE1)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y0E - LE1 * Sin(AE1)
        End If

        returnxy.X11 = temp_returnX1
        returnxy.Y11 = temp_returnY1

        If XY.X01 - XY.X0F < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X0F + LF1 * Cos(AF1)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X0F - LF1 * Cos(AF1)
        End If

        If XY.X01 - XY.X0F < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y0F + LF1 * Sin(AF1)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y0F - LF1 * Sin(AF1)
        End If

        returnxy.X12 = temp_returnX1
        returnxy.Y12 = temp_returnY1
over:
        Return returnxy
    End Function

    Public Function TwoPoint_14(ByVal x1, ByVal y1, ByVal x3, ByVal y3) As returnXY
        '函数用法：20个输入参数，前六个是拍照点PMA工具传过来的偏移量。
        '所有参与的数据必须为同一坐标系。

        Dim returnxy As returnXY
        'Dim L31, L31_, L41, L51, L61, L71, temp_returnX1, temp_returnY1, temp_returnR1 As Double
        'Dim L81, L91, LA1, LB1, LC1, LD1, LE1, LF1, LG1, LH1 As Double
        'Dim A41, A51, A61, A71, A81, A91, AA1, AB1, AC1, AD1, AE1, AF1, AG1, AH1 As Double
        Dim L31, L31_ As Double

        L31 = Sqrt(Pow((XY.X03 - XY.X01), 2) + Pow((XY.y03 - XY.y01), 2))

        L31_ = Sqrt(Pow((XY.X03 + x3 - XY.X01 - x1), 2) + Pow((XY.y03 + y3 - XY.y01 - y1), 2))

        If chanpin_zbx_R > 2 Or chanpin_zbx_R < -2 Or Abs(L31 - L31_) > Pget(2).ZPosCompensate Or y1 < Pget(2).XPosCompensate Or y1 > Pget(2).YPosCompensate Or y3 < Pget(2).XPosCompensate Or y3 > Pget(2).YPosCompensate Then

            returnxy.X1 = 900
            returnxy.Y1 = 900
            returnxy.X2 = 900
            returnxy.Y2 = 900
            returnxy.X3 = 900
            returnxy.Y3 = 900
            returnxy.X4 = 900
            returnxy.Y4 = 900
            returnxy.X5 = 900
            returnxy.Y5 = 900
            returnxy.X6 = 900
            returnxy.Y6 = 900
            returnxy.X7 = 900
            returnxy.Y7 = 900
            returnxy.X8 = 900
            returnxy.Y8 = 900
            returnxy.X9 = 900
            returnxy.Y9 = 900
            returnxy.X10 = 900
            returnxy.Y10 = 900
            returnxy.X11 = 900
            returnxy.Y11 = 900
            returnxy.X12 = 900
            returnxy.Y12 = 900
            returnxy.X13 = 900
            returnxy.Y13 = 900
            returnxy.X14 = 900
            returnxy.Y14 = 900
            returnxy.X15 = 900
            returnxy.Y15 = 900
            GoTo over
        Else
            returnxy.X1 = 0
            returnxy.Y1 = 0
            returnxy.X2 = 0
            returnxy.Y2 = 0
            returnxy.X3 = 0
            returnxy.Y3 = 0
            returnxy.X4 = 0
            returnxy.Y4 = 0
            returnxy.X5 = 0
            returnxy.Y5 = 0
            returnxy.X6 = 0
            returnxy.Y6 = 0
            returnxy.X7 = 0
            returnxy.Y7 = 0
            returnxy.X8 = 0
            returnxy.Y8 = 0
            returnxy.X9 = 0
            returnxy.Y9 = 0
            returnxy.X10 = 0
            returnxy.Y10 = 0
            returnxy.X11 = 0
            returnxy.Y11 = 0
            returnxy.X12 = 0
            returnxy.Y12 = 0
            returnxy.X13 = 0
            returnxy.Y13 = 0
            returnxy.X14 = 0
            returnxy.Y14 = 0
            returnxy.X15 = 0
            returnxy.Y15 = 0
        End If

over:
        Return returnxy
    End Function

    Public Function ThreePoint(ByVal x1, ByVal y1, ByVal x2, ByVal y2, ByVal x3, ByVal y3) As returnXY
        '函数用法：20个输入参数，前六个是拍照点PMA工具传过来的偏移量。
        '所有参与的数据必须为同一坐标系。

        Dim returnxy As returnXY
        Dim L21, L31, L23, L21_, L31_, L23_, L41, L42, L43, L51, L52, L53, L61, L62, L63, L71, L72, L73, temp_returnX1, temp_returnY1, temp_returnX2, temp_returnY2, temp_returnX3, temp_returnY3, temp_returnR1, temp_returnR2, temp_returnR3 As Double
        Dim L81, L82, L83, L91, L92, L93, LA1, LA2, LA3, LB1, LB2, LB3, LC1, LC2, LC3, LD1, LD2, LD3 As Double
        Dim A41, A42, A43, A51, A52, A53, A61, A62, A63, A71, A72, A73, A81, A82, A83, A91, A92, A93, AA1, AA2, AA3, AB1, AB2, AB3, AC1, AC2, AC3, AD1, AD2, AD3 As Double

        L21 = Sqrt(Pow((XY.X02 - XY.X01), 2) + Pow((XY.y02 - XY.y01), 2))
        L31 = Sqrt(Pow((XY.X03 - XY.X01), 2) + Pow((XY.y03 - XY.y01), 2))
        L23 = Sqrt(Pow((XY.X02 - XY.X03), 2) + Pow((XY.y02 - XY.y03), 2))

        L21_ = Sqrt(Pow((XY.X02 + x2 - XY.X01 - x1), 2) + Pow((XY.y02 + y2 - XY.y01 - y1), 2))
        L31_ = Sqrt(Pow((XY.X03 + x3 - XY.X01 - x1), 2) + Pow((XY.y03 + y3 - XY.y01 - y1), 2))
        L23_ = Sqrt(Pow((XY.X02 + x2 - XY.X03 - x3), 2) + Pow((XY.y02 + y2 - XY.y03 - y3), 2))

        If Abs(L21 - L21_) > 0.5 Or Abs(L31 - L31_) > 0.5 Or Abs(L23 - L23_) > 0.5 Or x1 > 100 Then
            returnxy.X1 = 900
            returnxy.Y1 = 900
            returnxy.X2 = 900
            returnxy.Y2 = 900
            returnxy.X3 = 900
            returnxy.Y3 = 900
            returnxy.X4 = 900
            returnxy.Y4 = 900
            returnxy.X5 = 900
            returnxy.Y5 = 900
            returnxy.X6 = 900
            returnxy.Y6 = 900
            returnxy.X7 = 900
            returnxy.Y7 = 900
            returnxy.X8 = 900
            returnxy.Y8 = 900
            returnxy.X9 = 900
            returnxy.Y9 = 900
            returnxy.X10 = 900
            returnxy.Y10 = 900
            GoTo over
        End If
        L41 = Sqrt(Pow((XY.X04 - XY.X01), 2) + Pow((XY.y04 - XY.y01), 2))
        L42 = Sqrt(Pow((XY.X04 - XY.X02), 2) + Pow((XY.y04 - XY.y02), 2))
        L43 = Sqrt(Pow((XY.X03 - XY.X04), 2) + Pow((XY.y03 - XY.y04), 2))
        L51 = Sqrt(Pow((XY.X05 - XY.X01), 2) + Pow((XY.y05 - XY.y01), 2))
        L52 = Sqrt(Pow((XY.X05 - XY.X02), 2) + Pow((XY.y05 - XY.y02), 2))
        L53 = Sqrt(Pow((XY.X03 - XY.X05), 2) + Pow((XY.y03 - XY.y05), 2))
        L61 = Sqrt(Pow((XY.X06 - XY.X01), 2) + Pow((XY.y06 - XY.y01), 2))
        L62 = Sqrt(Pow((XY.X06 - XY.X02), 2) + Pow((XY.y06 - XY.y02), 2))
        L63 = Sqrt(Pow((XY.X03 - XY.X06), 2) + Pow((XY.y03 - XY.y06), 2))
        L71 = Sqrt(Pow((XY.X07 - XY.X01), 2) + Pow((XY.y07 - XY.y01), 2))
        L72 = Sqrt(Pow((XY.X07 - XY.X02), 2) + Pow((XY.y07 - XY.y02), 2))
        L73 = Sqrt(Pow((XY.X03 - XY.X07), 2) + Pow((XY.y03 - XY.y07), 2))
        L81 = Sqrt(Pow((XY.X08 - XY.X01), 2) + Pow((XY.y08 - XY.y01), 2))
        L82 = Sqrt(Pow((XY.X08 - XY.X02), 2) + Pow((XY.y08 - XY.y02), 2))
        L83 = Sqrt(Pow((XY.X03 - XY.X08), 2) + Pow((XY.y03 - XY.y08), 2))
        L91 = Sqrt(Pow((XY.X09 - XY.X01), 2) + Pow((XY.y09 - XY.y01), 2))
        L92 = Sqrt(Pow((XY.X09 - XY.X02), 2) + Pow((XY.y09 - XY.y02), 2))
        L93 = Sqrt(Pow((XY.X03 - XY.X09), 2) + Pow((XY.y03 - XY.y09), 2))
        LA1 = Sqrt(Pow((XY.X0A - XY.X01), 2) + Pow((XY.y0A - XY.y01), 2))
        LA2 = Sqrt(Pow((XY.X0A - XY.X02), 2) + Pow((XY.y0A - XY.y02), 2))
        LA3 = Sqrt(Pow((XY.X03 - XY.X0A), 2) + Pow((XY.y03 - XY.y0A), 2))
        LB1 = Sqrt(Pow((XY.X0B - XY.X01), 2) + Pow((XY.y0B - XY.y01), 2))
        LB2 = Sqrt(Pow((XY.X0B - XY.X02), 2) + Pow((XY.y0B - XY.y02), 2))
        LB3 = Sqrt(Pow((XY.X03 - XY.X0B), 2) + Pow((XY.y03 - XY.y0B), 2))
        LC1 = Sqrt(Pow((XY.X0C - XY.X01), 2) + Pow((XY.y0C - XY.y01), 2))
        LC2 = Sqrt(Pow((XY.X0C - XY.X02), 2) + Pow((XY.y0C - XY.y02), 2))
        LC3 = Sqrt(Pow((XY.X03 - XY.X0C), 2) + Pow((XY.y03 - XY.y0C), 2))
        LD1 = Sqrt(Pow((XY.X0D - XY.X01), 2) + Pow((XY.y0D - XY.y01), 2))
        LD2 = Sqrt(Pow((XY.X0D - XY.X02), 2) + Pow((XY.y0D - XY.y02), 2))
        LD3 = Sqrt(Pow((XY.X03 - XY.X0D), 2) + Pow((XY.y03 - XY.y0D), 2))

        temp_returnR1 = Atan((XY.y02 - XY.y01) / (XY.X02 - XY.X01)) - Atan(((y2 + XY.y02) - (y1 + XY.y01)) / ((x2 + XY.X02) - (x1 + XY.X01)))
        temp_returnR2 = Atan((XY.y03 - XY.y02) / (XY.X03 - XY.X02)) - Atan(((y3 + XY.y03) - (y2 + XY.y02)) / ((x3 + XY.X03) - (x2 + XY.X02)))
        temp_returnR3 = Atan((XY.y01 - XY.y03) / (XY.X01 - XY.X03)) - Atan(((y1 + XY.y01) - (y3 + XY.y03)) / ((x1 + XY.X01) - (x3 + XY.X03)))

        If temp_returnR1 > 1 Then
            temp_returnR1 -= Acos(-1)
        End If
        If temp_returnR1 < -1 Then
            temp_returnR1 += Acos(-1)
        End If
        If temp_returnR2 > 1 Then
            temp_returnR2 -= Acos(-1)
        End If
        If temp_returnR2 < -1 Then
            temp_returnR2 += Acos(-1)
        End If
        If temp_returnR3 > 1 Then
            temp_returnR3 -= Acos(-1)
        End If
        If temp_returnR3 < -1 Then
            temp_returnR3 += Acos(-1)
        End If

        A41 = Atan((XY.y04 - XY.y01) / (XY.X04 - XY.X01)) - temp_returnR1
        A42 = Atan((XY.y04 - XY.y02) / (XY.X04 - XY.X02)) - temp_returnR2
        A43 = Atan((XY.y04 - XY.y03) / (XY.X04 - XY.X03)) - temp_returnR3

        A51 = Atan((XY.y05 - XY.y01) / (XY.X05 - XY.X01)) - temp_returnR1
        A52 = Atan((XY.y05 - XY.y02) / (XY.X05 - XY.X02)) - temp_returnR2
        A53 = Atan((XY.y05 - XY.y03) / (XY.X05 - XY.X03)) - temp_returnR3

        A61 = Atan((XY.y06 - XY.y01) / (XY.X06 - XY.X01)) - temp_returnR1
        A62 = Atan((XY.y06 - XY.y02) / (XY.X06 - XY.X02)) - temp_returnR2
        A63 = Atan((XY.y06 - XY.y03) / (XY.X06 - XY.X03)) - temp_returnR3

        A71 = Atan((XY.y07 - XY.y01) / (XY.X07 - XY.X01)) - temp_returnR1
        A72 = Atan((XY.y07 - XY.y02) / (XY.X07 - XY.X02)) - temp_returnR2
        A73 = Atan((XY.y07 - XY.y03) / (XY.X07 - XY.X03)) - temp_returnR3

        A81 = Atan((XY.y08 - XY.y01) / (XY.X08 - XY.X01)) - temp_returnR1
        A82 = Atan((XY.y08 - XY.y02) / (XY.X08 - XY.X02)) - temp_returnR2
        A83 = Atan((XY.y08 - XY.y03) / (XY.X08 - XY.X03)) - temp_returnR3

        A91 = Atan((XY.y09 - XY.y01) / (XY.X09 - XY.X01)) - temp_returnR1
        A92 = Atan((XY.y09 - XY.y02) / (XY.X09 - XY.X02)) - temp_returnR2
        A93 = Atan((XY.y09 - XY.y03) / (XY.X09 - XY.X03)) - temp_returnR3

        AA1 = Atan((XY.y0A - XY.y01) / (XY.X0A - XY.X01)) - temp_returnR1
        AA2 = Atan((XY.y0A - XY.y02) / (XY.X0A - XY.X02)) - temp_returnR2
        AA3 = Atan((XY.y0A - XY.y03) / (XY.X0A - XY.X03)) - temp_returnR3

        AB1 = Atan((XY.y0B - XY.y01) / (XY.X0B - XY.X01)) - temp_returnR1
        AB2 = Atan((XY.y0B - XY.y02) / (XY.X0B - XY.X02)) - temp_returnR2
        AB3 = Atan((XY.y0B - XY.y03) / (XY.X0B - XY.X03)) - temp_returnR3

        AC1 = Atan((XY.y0C - XY.y01) / (XY.X0C - XY.X01)) - temp_returnR1
        AC2 = Atan((XY.y0C - XY.y02) / (XY.X0C - XY.X02)) - temp_returnR2
        AC3 = Atan((XY.y0C - XY.y03) / (XY.X0C - XY.X03)) - temp_returnR3

        AD1 = Atan((XY.y0D - XY.y01) / (XY.X0D - XY.X01)) - temp_returnR1
        AD2 = Atan((XY.y0D - XY.y02) / (XY.X0D - XY.X02)) - temp_returnR2
        AD3 = Atan((XY.y0D - XY.y03) / (XY.X0D - XY.X03)) - temp_returnR3

        If XY.X01 - XY.X04 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X04 + L41 * Cos(A41)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X04 - L41 * Cos(A41)
        End If
        If XY.X02 - XY.X04 < 0 Then
            temp_returnX2 = x2 + XY.X02 - XY.X04 + L42 * Cos(A42)
        Else
            temp_returnX2 = x2 + XY.X02 - XY.X04 - L42 * Cos(A42)
        End If
        If XY.X03 - XY.X04 < 0 Then
            temp_returnX3 = x3 + XY.X03 - XY.X04 + L43 * Cos(A43)
        Else
            temp_returnX3 = x3 + XY.X03 - XY.X04 - L43 * Cos(A43)
        End If

        If XY.X01 - XY.X04 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y04 + L41 * Sin(A41)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y04 - L41 * Sin(A41)
        End If
        If XY.X02 - XY.X04 < 0 Then
            temp_returnY2 = y2 + XY.y02 - XY.y04 + L42 * Sin(A42)
        Else
            temp_returnY2 = y2 + XY.y02 - XY.y04 - L42 * Sin(A42)
        End If
        If XY.X03 - XY.X04 < 0 Then
            temp_returnY3 = y3 + XY.y03 - XY.y04 + L43 * Sin(A43)
        Else
            temp_returnY3 = y3 + XY.y03 - XY.y04 - L43 * Sin(A43)
        End If

        returnxy.X1 = (temp_returnX1 + temp_returnX2 + temp_returnX3) / 3
        returnxy.Y1 = (temp_returnY1 + temp_returnY2 + temp_returnY3) / 3

        If XY.X01 - XY.X05 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X05 + L51 * Cos(A51)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X05 - L51 * Cos(A51)
        End If
        If XY.X02 - XY.X05 < 0 Then
            temp_returnX2 = x2 + XY.X02 - XY.X05 + L52 * Cos(A52)
        Else
            temp_returnX2 = x2 + XY.X02 - XY.X05 - L52 * Cos(A52)
        End If
        If XY.X03 - XY.X05 < 0 Then
            temp_returnX3 = x3 + XY.X03 - XY.X05 + L53 * Cos(A53)
        Else
            temp_returnX3 = x3 + XY.X03 - XY.X05 - L53 * Cos(A53)
        End If

        If XY.X01 - XY.X05 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y05 + L51 * Sin(A51)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y05 - L51 * Sin(A51)
        End If
        If XY.X02 - XY.X05 < 0 Then
            temp_returnY2 = y2 + XY.y02 - XY.y05 + L52 * Sin(A52)
        Else
            temp_returnY2 = y2 + XY.y02 - XY.y05 - L52 * Sin(A52)
        End If
        If XY.X03 - XY.X05 < 0 Then
            temp_returnY3 = y3 + XY.y03 - XY.y05 + L53 * Sin(A53)
        Else
            temp_returnY3 = y3 + XY.y03 - XY.y05 - L53 * Sin(A53)
        End If

        returnxy.X2 = (temp_returnX1 + temp_returnX2 + temp_returnX3) / 3
        returnxy.Y2 = (temp_returnY1 + temp_returnY2 + temp_returnY3) / 3

        If XY.X01 - XY.X06 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X06 + L61 * Cos(A61)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X06 - L61 * Cos(A61)
        End If
        If XY.X02 - XY.X06 < 0 Then
            temp_returnX2 = x2 + XY.X02 - XY.X06 + L62 * Cos(A62)
        Else
            temp_returnX2 = x2 + XY.X02 - XY.X06 - L62 * Cos(A62)
        End If
        If XY.X03 - XY.X06 < 0 Then
            temp_returnX3 = x3 + XY.X03 - XY.X06 + L63 * Cos(A63)
        Else
            temp_returnX3 = x3 + XY.X03 - XY.X06 - L63 * Cos(A63)
        End If

        If XY.X01 - XY.X06 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y06 + L61 * Sin(A61)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y06 - L61 * Sin(A61)
        End If
        If XY.X02 - XY.X06 < 0 Then
            temp_returnY2 = y2 + XY.y02 - XY.y06 + L62 * Sin(A62)
        Else
            temp_returnY2 = y2 + XY.y02 - XY.y06 - L62 * Sin(A62)
        End If
        If XY.X03 - XY.X06 < 0 Then
            temp_returnY3 = y3 + XY.y03 - XY.y06 + L63 * Sin(A63)
        Else
            temp_returnY3 = y3 + XY.y03 - XY.y06 - L63 * Sin(A63)
        End If

        returnxy.X3 = (temp_returnX1 + temp_returnX2 + temp_returnX3) / 3
        returnxy.Y3 = (temp_returnY1 + temp_returnY2 + temp_returnY3) / 3

        If XY.X01 - XY.X07 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X07 + L71 * Cos(A71)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X07 - L71 * Cos(A71)
        End If
        If XY.X02 - XY.X07 < 0 Then
            temp_returnX2 = x2 + XY.X02 - XY.X07 + L72 * Cos(A72)
        Else
            temp_returnX2 = x2 + XY.X02 - XY.X07 - L72 * Cos(A72)
        End If
        If XY.X03 - XY.X07 < 0 Then
            temp_returnX3 = x3 + XY.X03 - XY.X07 + L73 * Cos(A73)
        Else
            temp_returnX3 = x3 + XY.X03 - XY.X07 - L73 * Cos(A73)
        End If

        If XY.X01 - XY.X07 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y07 + L71 * Sin(A71)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y07 - L71 * Sin(A71)
        End If
        If XY.X02 - XY.X07 < 0 Then
            temp_returnY2 = y2 + XY.y02 - XY.y07 + L72 * Sin(A72)
        Else
            temp_returnY2 = y2 + XY.y02 - XY.y07 - L72 * Sin(A72)
        End If
        If XY.X03 - XY.X07 < 0 Then
            temp_returnY3 = y3 + XY.y03 - XY.y07 + L73 * Sin(A73)
        Else
            temp_returnY3 = y3 + XY.y03 - XY.y07 - L73 * Sin(A73)
        End If

        returnxy.X4 = (temp_returnX1 + temp_returnX2 + temp_returnX3) / 3
        returnxy.Y4 = (temp_returnY1 + temp_returnY2 + temp_returnY3) / 3

        If XY.X01 - XY.X08 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X08 + L81 * Cos(A81)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X08 - L81 * Cos(A81)
        End If
        If XY.X02 - XY.X08 < 0 Then
            temp_returnX2 = x2 + XY.X02 - XY.X08 + L82 * Cos(A82)
        Else
            temp_returnX2 = x2 + XY.X02 - XY.X08 - L82 * Cos(A82)
        End If
        If XY.X03 - XY.X08 < 0 Then
            temp_returnX3 = x3 + XY.X03 - XY.X08 + L83 * Cos(A83)
        Else
            temp_returnX3 = x3 + XY.X03 - XY.X08 - L83 * Cos(A83)
        End If

        If XY.X01 - XY.X08 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y08 + L81 * Sin(A81)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y08 - L81 * Sin(A81)
        End If
        If XY.X02 - XY.X08 < 0 Then
            temp_returnY2 = y2 + XY.y02 - XY.y08 + L82 * Sin(A82)
        Else
            temp_returnY2 = y2 + XY.y02 - XY.y08 - L82 * Sin(A82)
        End If
        If XY.X03 - XY.X08 < 0 Then
            temp_returnY3 = y3 + XY.y03 - XY.y08 + L83 * Sin(A83)
        Else
            temp_returnY3 = y3 + XY.y03 - XY.y08 - L83 * Sin(A83)
        End If

        returnxy.X5 = (temp_returnX1 + temp_returnX2 + temp_returnX3) / 3
        returnxy.Y5 = (temp_returnY1 + temp_returnY2 + temp_returnY3) / 3

        If XY.X01 - XY.X09 < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X09 + L91 * Cos(A91)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X09 - L91 * Cos(A91)
        End If
        If XY.X02 - XY.X09 < 0 Then
            temp_returnX2 = x2 + XY.X02 - XY.X09 + L92 * Cos(A92)
        Else
            temp_returnX2 = x2 + XY.X02 - XY.X09 - L92 * Cos(A92)
        End If
        If XY.X03 - XY.X09 < 0 Then
            temp_returnX3 = x3 + XY.X03 - XY.X09 + L93 * Cos(A93)
        Else
            temp_returnX3 = x3 + XY.X03 - XY.X09 - L93 * Cos(A93)
        End If

        If XY.X01 - XY.X09 < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y09 + L91 * Sin(A91)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y09 - L91 * Sin(A91)
        End If
        If XY.X02 - XY.X09 < 0 Then
            temp_returnY2 = y2 + XY.y02 - XY.y09 + L92 * Sin(A92)
        Else
            temp_returnY2 = y2 + XY.y02 - XY.y09 - L92 * Sin(A92)
        End If
        If XY.X03 - XY.X09 < 0 Then
            temp_returnY3 = y3 + XY.y03 - XY.y09 + L93 * Sin(A93)
        Else
            temp_returnY3 = y3 + XY.y03 - XY.y09 - L93 * Sin(A93)
        End If

        returnxy.X6 = (temp_returnX1 + temp_returnX2 + temp_returnX3) / 3
        returnxy.Y6 = (temp_returnY1 + temp_returnY2 + temp_returnY3) / 3

        If XY.X01 - XY.X0A < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X0A + LA1 * Cos(AA1)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X0A - LA1 * Cos(AA1)
        End If
        If XY.X02 - XY.X0A < 0 Then
            temp_returnX2 = x2 + XY.X02 - XY.X0A + LA2 * Cos(AA2)
        Else
            temp_returnX2 = x2 + XY.X02 - XY.X0A - LA2 * Cos(AA2)
        End If
        If XY.X03 - XY.X0A < 0 Then
            temp_returnX3 = x3 + XY.X03 - XY.X0A + LA3 * Cos(AA3)
        Else
            temp_returnX3 = x3 + XY.X03 - XY.X0A - LA3 * Cos(AA3)
        End If

        If XY.X01 - XY.X0A < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y0A + LA1 * Sin(AA1)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y0A - LA1 * Sin(AA1)
        End If
        If XY.X02 - XY.X0A < 0 Then
            temp_returnY2 = y2 + XY.y02 - XY.y0A + LA2 * Sin(AA2)
        Else
            temp_returnY2 = y2 + XY.y02 - XY.y0A - LA2 * Sin(AA2)
        End If
        If XY.X03 - XY.X0A < 0 Then
            temp_returnY3 = y3 + XY.y03 - XY.y0A + LA3 * Sin(AA3)
        Else
            temp_returnY3 = y3 + XY.y03 - XY.y0A - LA3 * Sin(AA3)
        End If

        returnxy.X7 = (temp_returnX1 + temp_returnX2 + temp_returnX3) / 3
        returnxy.Y7 = (temp_returnY1 + temp_returnY2 + temp_returnY3) / 3

        If XY.X01 - XY.X0B < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X0B + LB1 * Cos(AB1)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X0B - LB1 * Cos(AB1)
        End If
        If XY.X02 - XY.X0B < 0 Then
            temp_returnX2 = x2 + XY.X02 - XY.X0B + LB2 * Cos(AB2)
        Else
            temp_returnX2 = x2 + XY.X02 - XY.X0B - LB2 * Cos(AB2)
        End If
        If XY.X03 - XY.X0B < 0 Then
            temp_returnX3 = x3 + XY.X03 - XY.X0B + LB3 * Cos(AB3)
        Else
            temp_returnX3 = x3 + XY.X03 - XY.X0B - LB3 * Cos(AB3)
        End If

        If XY.X01 - XY.X0B < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y0B + LB1 * Sin(AB1)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y0B - LB1 * Sin(AB1)
        End If
        If XY.X02 - XY.X0B < 0 Then
            temp_returnY2 = y2 + XY.y02 - XY.y0B + LB2 * Sin(AB2)
        Else
            temp_returnY2 = y2 + XY.y02 - XY.y0B - LB2 * Sin(AB2)
        End If
        If XY.X03 - XY.X0B < 0 Then
            temp_returnY3 = y3 + XY.y03 - XY.y0B + LB3 * Sin(AB3)
        Else
            temp_returnY3 = y3 + XY.y03 - XY.y0B - LB3 * Sin(AB3)
        End If

        returnxy.X8 = (temp_returnX1 + temp_returnX2 + temp_returnX3) / 3
        returnxy.Y8 = (temp_returnY1 + temp_returnY2 + temp_returnY3) / 3

        If XY.X01 - XY.X0C < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X0C + LC1 * Cos(AC1)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X0C - LC1 * Cos(AC1)
        End If
        If XY.X02 - XY.X0C < 0 Then
            temp_returnX2 = x2 + XY.X02 - XY.X0C + LC2 * Cos(AC2)
        Else
            temp_returnX2 = x2 + XY.X02 - XY.X0C - LC2 * Cos(AC2)
        End If
        If XY.X03 - XY.X0C < 0 Then
            temp_returnX3 = x3 + XY.X03 - XY.X0C + LC3 * Cos(AC3)
        Else
            temp_returnX3 = x3 + XY.X03 - XY.X0C - LC3 * Cos(AC3)
        End If

        If XY.X01 - XY.X0C < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y0C + LC1 * Sin(AC1)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y0C - LC1 * Sin(AC1)
        End If
        If XY.X02 - XY.X0C < 0 Then
            temp_returnY2 = y2 + XY.y02 - XY.y0C + LC2 * Sin(AC2)
        Else
            temp_returnY2 = y2 + XY.y02 - XY.y0C - LC2 * Sin(AC2)
        End If
        If XY.X03 - XY.X0C < 0 Then
            temp_returnY3 = y3 + XY.y03 - XY.y0C + LC3 * Sin(AC3)
        Else
            temp_returnY3 = y3 + XY.y03 - XY.y0C - LC3 * Sin(AC3)
        End If

        returnxy.X9 = (temp_returnX1 + temp_returnX2 + temp_returnX3) / 3
        returnxy.Y9 = (temp_returnY1 + temp_returnY2 + temp_returnY3) / 3

        If XY.X01 - XY.X0D < 0 Then
            temp_returnX1 = x1 + XY.X01 - XY.X0D + LD1 * Cos(AD1)
        Else
            temp_returnX1 = x1 + XY.X01 - XY.X0D - LD1 * Cos(AD1)
        End If
        If XY.X02 - XY.X0D < 0 Then
            temp_returnX2 = x2 + XY.X02 - XY.X0D + LD2 * Cos(AD2)
        Else
            temp_returnX2 = x2 + XY.X02 - XY.X0D - LD2 * Cos(AD2)
        End If
        If XY.X03 - XY.X0D < 0 Then
            temp_returnX3 = x3 + XY.X03 - XY.X0D + LD3 * Cos(AD3)
        Else
            temp_returnX3 = x3 + XY.X03 - XY.X0D - LD3 * Cos(AD3)
        End If

        If XY.X01 - XY.X0D < 0 Then
            temp_returnY1 = y1 + XY.y01 - XY.y0D + LD1 * Sin(AD1)
        Else
            temp_returnY1 = y1 + XY.y01 - XY.y0D - LD1 * Sin(AD1)
        End If
        If XY.X02 - XY.X0D < 0 Then
            temp_returnY2 = y2 + XY.y02 - XY.y0D + LD2 * Sin(AD2)
        Else
            temp_returnY2 = y2 + XY.y02 - XY.y0D - LD2 * Sin(AD2)
        End If
        If XY.X03 - XY.X0D < 0 Then
            temp_returnY3 = y3 + XY.y03 - XY.y0D + LD3 * Sin(AD3)
        Else
            temp_returnY3 = y3 + XY.y03 - XY.y0D - LD3 * Sin(AD3)
        End If

        returnxy.X10 = (temp_returnX1 + temp_returnX2 + temp_returnX3) / 3
        returnxy.Y10 = (temp_returnY1 + temp_returnY2 + temp_returnY3) / 3
over:
        Return returnxy
    End Function

    Function LoadProSetting(ByVal SettingPath As String) As Boolean
        Try

            Dim fileNum, LineNum, MidNum As Integer
            '文件内容
            Dim fileContents As String
            '文件内容数组,按照每行分隔
            Dim fileInfo() As String
            '一行的数据,包括
            Dim strRowContent() As String

            '获取文件号
            fileNum = FreeFile()
            '打开文件
            If Dir(SettingPath) = "" Then
                Return False
            End If
            FileOpen(fileNum, SettingPath, OpenMode.Binary) ''''''']]]]]new function for mml  为什么以2进制文件打开呢？
            '给fileContents分配内存
            fileContents = Space(LOF(fileNum)) ''''''']]]]]new function for mml
            '将文件内容放入fileContents中
            FileGet(fileNum, fileContents) ''''''']]]]]new function for mml
            '关闭文件
            FileClose(fileNum) ''''''']]]]]new function for mml
            '将文件内容按照vbCrLf分隔到fileInfo数组
            fileInfo = Split(fileContents, vbCrLf) ''''''']]]]]new function for mml
            LineNum = 0
            LineNum = UBound(fileInfo)
            Dim k1 As Integer

            Dim i As Integer
            For k1 = 1 To LineNum + 1
                '从fileInfo(i-1)数据(对应文件中第i行内容)再分隔字符,按照连续空格来分隔
                strRowContent = Split(fileInfo(k1 - 1), vbTab) ''以,来分隔
                MidNum = UBound(strRowContent)
                If MidNum = 5 And strRowContent(0) <> "XCPro Data ver1.0.0" Then
                    '  gMotoScale(i) = strRowContent(5)
                    i += 1
                End If

                Application.DoEvents()
            Next k1
            Return True
        Catch ex As Exception
            MsgBox("读取参数错误：" & ex.Message)
            Return False
        End Try

    End Function

    Function SaveProSetting(ByVal SettingPath As String, ByVal Name As String) As Boolean
        Try
            '文件名
            Dim strSaveFile As String
            '文件号
            Dim fileNum As Integer
            Dim k1 As Int16
            '从文件中提取位置信息
            '取当前文件夹下的指定文件
            If Dir(SettingPath, FileAttribute.Directory) = "" Then
                MkDir(SettingPath)
            End If
            strSaveFile = SettingPath & "\" & Name
            '获取文件号
            fileNum = FreeFile()
            '打开文件
            FileOpen(fileNum, strSaveFile, OpenMode.Output)
            '存储到文件中
            '版本号：
            Print(fileNum, "XCPro Data ver1.0.0" & vbCrLf)
            For k1 = 0 To 10 '0-10个马达
                '     Print(fileNum, "MotoParam" & vbTab & gHomeV(k1) & vbTab & gOffset(k1) & vbTab & gStartV(k1) & vbTab & gMaxV(k1) & vbTab & gAcc(k1) & vbCrLf)
            Next
            '关闭文件
            FileClose(fileNum)

            Return True
        Catch ex As Exception
            MsgBox("保存参数错误：" & ex.Message)
            Return False
        End Try
    End Function

    '判断7250卡输入，index：输入端口号（0~15），该端口有输入则返回true，否则返回false
    Public Function read_7250_input(ByVal index As Integer, Optional ByVal InputData As Integer = 0, Optional ByVal IsUseInput As Boolean = False) As Boolean
        Dim Di_Data As Integer
        If IsUseInput Then
            If InputData And 2 ^ (index) Then
                Return True
            Else
                Return False
            End If
        Else
            Di_Data = 0
            DI_ReadPort(0, 0, Di_Data)
            If Di_Data And 2 ^ (index) Then
                Return True
            Else
                Return False
            End If
        End If

    End Function

    '725卡输出
    Public Sub add_7250_output(ByVal index As Integer)
        Try
            Dim Do_Data As Integer = 0
            DO_ReadPort(gIOCard, 0, Do_Data)

            If Not Do_Data And 2 ^ (index) Then
                Do_Data = Do_Data + 2 ^ (index)
            End If

            DO_WritePort(gIOCard, 0, Do_Data)
        Catch ex As Exception
        End Try
    End Sub

    '725卡输出
    Public Sub exclu_725_output(ByVal index As Integer)
        Try
            Dim Do_Data As Integer = 0
            DO_ReadPort(gIOCard, 0, Do_Data)
            If Do_Data And 2 ^ (index) Then
                Do_Data = Do_Data - 2 ^ (index)
            End If
            DO_WritePort(gIOCard, 0, Do_Data)
        Catch ex As Exception
        End Try
    End Sub

    Public Sub WriteInspecLog(ByRef Textbox As System.Windows.Forms.ToolStripComboBox, ByVal str As String)
        mut.WaitOne()
        Dim filePath As String = CD_Dir & "上位机资料" & "\log"
        If Dir(filePath, FileAttribute.Directory) = "" Then
            MkDir(filePath)
        End If
        '文件名
        Dim strSaveFilename As String
        '文件号
        Dim fileNum As Integer
        strSaveFilename = filePath & "\" & "System_Histroy_" & Format(Date.Now.Date, "yyyyMMdd") & ".txt"
        '获取文件号
        fileNum = FreeFile()
        '打开文件
        FileOpen(fileNum, strSaveFilename, OpenMode.Append)

        '存储文件title
        Print(fileNum, "System_Histroy_" & Date.Now & vbTab)

        '存储到文件中
        Print(fileNum, str & vbCrLf)
        '关闭文件
        FileClose(fileNum)
        '显示
        Textbox.Items.Insert(0, Date.Now & vbTab & str)
        Textbox.SelectedIndex = 0
        mut.ReleaseMutex()

    End Sub

    Function DeCodeModBusRTU(ByVal code() As Byte, ByVal str As String) As Integer '计算接收到的值是否有效，并返回意义；这里表示相机序号
        Dim tmp1, tmp2 As Byte
        If Not gIsRun Then
            Return 0
        End If
        If gIsModBus Then '如果通过modbus通讯
            If code(0) = &H1 Then
                Call CRC16(code, UBound(code) - 2, tmp1, tmp2) '调用CRC16计算函数
                If code(6) = tmp1 And code(7) = tmp2 Then
                    Select Case code(3)
                        Case 1 '第一个相机定位
                            Return 1
                        Case 2
                            Return 2
                        Case 3
                            Return 3
                        Case 4
                            Return 4
                        Case 5
                            Return 5
                        Case 6
                            Return 6
                        Case 7
                            Return 7
                        Case 8
                            Return 8
                    End Select
                Else
                    Return 0
                End If
            Else
                Return 0
            End If
        Else '如果是自定义通讯
            Dim strRowContent() As String
            Dim midNum As Integer
            strRowContent = Split(str, ",") ''以,来分隔
            midNum = UBound(strRowContent)
            If midNum = 0 Then
                If 1 Then
                    Return Val(strRowContent(0))
                Else
                    Return 0
                End If
            Else
                Return 0
            End If
        End If

    End Function

    Function DeCodeModBusRTUModel(ByVal str As String) As Integer '计算接收到的值是否有效，并返回意义'这里表示螺丝模板型号
        If Not gIsRun Then
            Return 0
        End If
        Dim strRowContent() As String
        Dim midNum As Integer
        strRowContent = Split(str, ",") ''以,来分隔
        midNum = UBound(strRowContent)
        If midNum = 2 Then
            If strRowContent(0) = "SR" Then
                Return Val(strRowContent(2))
            Else
                Return 0
            End If
        Else
            Return 0
        End If
    End Function

    Function DeCodeModBusRTUPN(ByVal str As String) As String '计算接收到的值是否有效，并返回意义'这里表示产品模板型号
        If Not gIsRun Then
            Return 0
        End If
        Dim strRowContent() As String
        Dim midNum As Integer
        strRowContent = Split(str, ",") ''以,来分隔
        midNum = UBound(strRowContent)
        If midNum = 2 Then
            If strRowContent(0) = "PN" Then
                Return (strRowContent(1))
            Else
                Return 0
            End If
        Else
            Return 0
        End If
    End Function

    Public Function writeModBusRTUPos(ByRef Com As IO.Ports.SerialPort, ByVal Value As offset, ByVal Cam_Index As Byte, ByRef Textbox As System.Windows.Forms.ToolStripComboBox) As Boolean  'modBus写入POS
        Try
            Dim ihighValue, iLowValue As Byte
            Dim i As Integer
            Dim SendStr(7) As Byte
            Dim codeStr As String = ""
            If gIsModBus Then '如果通过modbus通讯
                SendStr(0) = &H1 '编码器通信地址
                SendStr(1) = &H4 '命令字
                SendStr(2) = &H4 '数据长度
                SepHiLow(Int(Value.x * 100), ihighValue, iLowValue)
                SendStr(3) = ihighValue '数据1
                SendStr(4) = iLowValue '数据1
                SepHiLow(Int(Value.y * 100), ihighValue, iLowValue)
                SendStr(5) = ihighValue  '数据2
                SendStr(6) = iLowValue '数据2
                Call CRC16(SendStr, UBound(SendStr) - 2, SendStr(7), SendStr(8)) '调用CRC16计算函数
                mutSp1.WaitOne()
                Com.Write(SendStr, 0, 9)
                mutSp1.ReleaseMutex()
                For i = 0 To 8
                    codeStr += SendStr(i)
                Next
            Else '自定义通讯
                GenComCode(Cam_Index, SendStr)
                Com.Write(SendStr, 0, 8)
                For i = 0 To 7
                    codeStr += SendStr(i).ToString
                Next
            End If
            mut.WaitOne()
            WriteInspecLog(Textbox, "SendComData" & vbTab & codeStr.ToString) '错误信息写入log Textbox.Text = Date.Now & vbTab & codeStr
            mut.ReleaseMutex()
        Catch ex As Exception
            MsgBox("串口发送出错！" & ex.Message)
        End Try
    End Function

    Public Function writeModBusRTUCheck(ByRef Com As IO.Ports.SerialPort, ByVal Value As offset, ByVal Cam_Index As Byte) As Boolean  'modBus写入check
        Try

            Dim SendStr(7) As Byte
            Dim codeStr As String = ""
            If gIsModBus Then '如果通过modbus通讯
                SendStr(0) = &H1 '编码器通信地址
                SendStr(1) = &H4 '命令字
                SendStr(2) = &H4 '数据长度
                If Value.IsPass Then
                    SendStr(3) = 1 '数据1
                    SendStr(4) = 1 '数据1

                    SendStr(5) = 1  '数据2
                    SendStr(6) = 1 '数据2
                Else
                    SendStr(3) = 0 '数据1
                    SendStr(4) = 0 '数据1

                    SendStr(5) = 0  '数据2
                    SendStr(6) = 0 '数据2
                End If
                Call CRC16(SendStr, UBound(SendStr) - 2, SendStr(7), SendStr(8)) '调用CRC16计算函数
                Com.Write(SendStr, 0, 9)
            Else '自定义通讯
                GenComCode(Cam_Index, SendStr)
                Com.Write(SendStr, 0, 8)
                Dim i As Integer

                For i = 0 To 7
                    codeStr += SendStr(i).ToString
                Next
            End If
        Catch ex As Exception
            MsgBox("串口发送出错！" & ex.Message)
        End Try
    End Function

    '按ASC码发送
    'Public Function GenComCode(ByRef code As String) As Boolean '生成与PLC通讯的数
    '    Dim ihighValue, iLowValue As Byte
    '    Dim i As Integer
    '    Dim tmp As UInteger
    '    For i = 0 To Cam_num - 1
    '        '写入偏移
    '        If gPosResult(i).x > 0 Then '判断符号
    '            code += "1"
    '        Else
    '            code += "0"
    '        End If

    '        code += Int(gPosResult(i).x * 100).ToString  'x高位

    '        If gPosResult(i).y > 0 Then '判断符号
    '            code += "1"
    '        Else
    '            code += "0"
    '        End If
    '        code += Int(gPosResult(i).y * 100).ToString 'y高位

    '    Next
    '    '写入检测值
    '    For i = 0 To Cam_num - 1
    '        If gPosResult(i).IsPass Then
    '            code += "1"
    '        Else
    '            code += "0"
    '        End If
    '    Next
    '    '写入错误代码
    '    For i = 0 To Cam_num - 1
    '        If gPosResult(i).ErrCode = 0 Then
    '            code += "1"
    '        Else
    '            code += "0"
    '        End If
    '    Next
    '    Return True
    'End Function
    ' 按字节发送，PLC无法组合高8位低8位形成数据
    Public Function GenComCode(ByVal Cma_index As Integer, ByRef code() As Byte) As Boolean '生成与PLC通讯的数
        Dim ihighValue, iLowValue As Byte
        '写入偏移
        If gPosResult(Cma_index).x > 0 Then '判断符号
            code(0) = 1
        Else
            code(0) = 0
        End If
        SepHiLow(Int(gPosResult(Cma_index).x * 100), ihighValue, iLowValue)
        code(1) = iLowValue  'x高位
        code(2) = ihighValue 'x地位
        If gPosResult(Cma_index).y > 0 Then '判断符号
            code(3) = 1
        Else
            code(3) = 0
        End If
        SepHiLow(Int(gPosResult(Cma_index).y * 100), ihighValue, iLowValue)
        code(4) = iLowValue 'y高位
        code(5) = ihighValue  'y地位
        '写入检测值
        If gPosResult(Cma_index).IsPass Then
            code(6) = 1
        Else
            code(6) = 0
        End If
        '写入错误代码
        code(7) = gPosResult(Cma_index).ErrCode
        Return True
    End Function

    Public Function SepHiLow(ByVal value As Integer, ByRef ihighValue As Byte, ByRef iLowValue As Byte) As Boolean '分隔高8位低位
        Dim iValue As String

        iValue = Abs(value).ToString

        ihighValue = Int(Val(iValue) / 100)
        iLowValue = CByte(Strings.Right(iValue, 2))
        'iHighValue = ((iValue And &HFF00) \ &H100) And &HFF
        '  iLowValue = iValue And &HFF
        Return True
    End Function

    Function CRC16(ByVal data() As Byte, ByVal i As Integer, ByRef ReturnDatalo As Byte, ByRef ReturnDatahi As Byte) As String 'CRC16效验
        Dim CRC16Lo As Byte, CRC16Hi As Byte      'CRC寄存器
        Dim CL As Byte, CH As Byte                '多项式码&HA001
        Dim SaveHi As Byte, SaveLo As Byte
        Dim Flag As Integer
        CRC16Lo = &HFF
        CRC16Hi = &HFF
        CL = &H1
        CH = &HA0
        For i = 0 To UBound(data) - 2
            CRC16Lo = CRC16Lo Xor data(i) '每一个数据与CRC寄存器进行异或
            For Flag = 0 To 7
                SaveHi = CRC16Hi
                SaveLo = CRC16Lo
                CRC16Hi = CRC16Hi \ 2            '高位右移一位
                CRC16Lo = CRC16Lo \ 2            '低位右移一位
                If ((SaveHi And &H1) = &H1) Then '如果高位字节最后一位为1
                    CRC16Lo = CRC16Lo Or &H80      '则低位字节右移后前面补1
                End If                           '否则自动补0
                If ((SaveLo And &H1) = &H1) Then '如果LSB为1，则与多项式码进行异或
                    CRC16Hi = CRC16Hi Xor CH
                    CRC16Lo = CRC16Lo Xor CL
                End If
            Next Flag
        Next i
        ReturnDatahi = CRC16Hi              'CRC高位
        ReturnDatalo = CRC16Lo              'CRC低位
    End Function

    Public Sub UploadMessage(ByVal data As String, ByVal address As String)
        Try
            If newset(7) Then
                'For Each pro As Process In Process.GetProcesses()
                '                    If pro.ProcessName = "Upload" Or pro.ProcessName = "数据上传" Then
                '                        GoTo ddd
                '                    End If
                '                Next
                '                FrmMain.OpenUploadProcess()
                'ddd:
                Dim WM_SETFOCUS As IntPtr = &H7
                Dim WM_SETTEXT As IntPtr = &HC
                Dim lngCalculator As IntPtr = FindWindow(vbNullString, "数据上传")
                Dim Line As IntPtr = FindWindowEx(lngCalculator, 0, vbNullString, address)
                Dim j As Integer = SendMessage(Line, WM_SETTEXT, 0, data)
            End If
        Catch ex As Exception
            MsgBox("UploadMessage:" & ex.Message.ToString & ex.StackTrace.ToString)
        End Try
    End Sub

    '对mysql进行查询操作
    Public Function SearchMysql(ByVal sql As String) As DataSet
        Try

            Dim str As String = "Server=" & MySQLIP & ";User ID=" & MySQLUserName & ";Password=" & MySQLPassWord & ";Database=" & MySQLDataBase & ";CharSet=utf8;pooling=true;Allow Zero Datetime=true"
            Dim con As New MySqlConnection(str)
            con.Open()
            Dim cmd As New MySqlCommand(sql, con)
            Dim ada As New MySqlDataAdapter(cmd)
            Dim ds As New DataSet()
            ada.Fill(ds)
            con.Close()
            Return ds
        Catch ex As Exception
            MessageBox.Show("SearchMysql:" & ex.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return Nothing
        End Try
    End Function

    '对mysql进行增删改操作
    Public Function HandleMysql(ByVal sql As String) As Integer
        Dim trans As MySqlTransaction = Nothing
        Try
            Dim str As String = "Server=" & MySQLIP & ";User ID=" & MySQLUserName & ";Password=" & MySQLPassWord & ";Database=" & MySQLDataBase & ";CharSet=utf8;pooling=true;Allow Zero Datetime=true"
            Dim con As New MySqlConnection(str)
            con.Open()
            Dim cmd As New MySqlCommand(sql, con)
            trans = con.BeginTransaction()
            cmd.Transaction = trans
            Dim i As Integer = cmd.ExecuteNonQuery()
            trans.Commit()
            con.Close()
            Return i
        Catch ex As Exception
            trans.Rollback()
            MessageBox.Show("HandleMysql:" & ex.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return 0
        End Try
    End Function

    Public Sub CopyMysql(ByVal oldName As String, ByVal newName As String)
        Try
            Dim sqlFlaf As String = "select * from cad_point where Product='" & newName & "'"
            Dim tableFlag As DataSet = SearchMysql(sqlFlaf)
            If tableFlag.Tables(0).Rows.Count < 10 Then
                Dim sql As String = "select * from archpara where Product='" & oldName & "'"
                Dim sql1 As String = "select * from cad_point where Product='" & oldName & "'"
                Dim sql2 As String = "select * from passset where Product='" & oldName & "'"
                Dim sql3 As String = "select * from photo_point where Product='" & oldName & "'"
                Dim sql4 As String = "select * from pointpara where Product='" & oldName & "'"
                'Dim sql5 As String = "select * from pointway where Product='" & oldName & "'"
                Dim sql6 As String = "select * from robot_point where Product='" & oldName & "'"
                Dim sql7 As String = "select * from timerdelay where Product='" & oldName & "'"
                Dim table As DataSet = SearchMysql(sql)
                For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                    Dim InSql As String = "insert into archpara(ArchNO,UpMove,DownMove,UpPass,DownPass,Product) values('" & table.Tables(0).Rows(i)("ArchNO") & "','" & table.Tables(0).Rows(i)("UpMove") & "','" & table.Tables(0).Rows(i)("DownMove") & "','" & table.Tables(0).Rows(i)("UpPass") & "','" & table.Tables(0).Rows(i)("DownPass") & "','" & newName & "')"
                    HandleMysql(InSql)
                Next
                table = SearchMysql(sql1)
                For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                    Dim InSql As String = "insert into cad_point(PointName,x,y,z,c,FLG1,Product) values('" & table.Tables(0).Rows(i)("PointName") & "','" & table.Tables(0).Rows(i)("x") & "','" & table.Tables(0).Rows(i)("y") & "','" & table.Tables(0).Rows(i)("z") & "','" & table.Tables(0).Rows(i)("c") & "','" & table.Tables(0).Rows(i)("FLG1") & "','" & newName & "')"
                    HandleMysql(InSql)
                Next
                table = SearchMysql(sql2)
                For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                    Dim InSql As String = "insert into passset(PassName,x,y,z,c,Product) values('" & table.Tables(0).Rows(i)("PassName") & "','" & table.Tables(0).Rows(i)("x") & "','" & table.Tables(0).Rows(i)("y") & "','" & table.Tables(0).Rows(i)("z") & "','" & table.Tables(0).Rows(i)("c") & "','" & newName & "')"
                    HandleMysql(InSql)
                Next
                table = SearchMysql(sql3)
                For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                    Dim InSql As String = "insert into photo_point(PointName,x,y,z,c,FLG1,Product) values('" & table.Tables(0).Rows(i)("PointName") & "','" & table.Tables(0).Rows(i)("x") & "','" & table.Tables(0).Rows(i)("y") & "','" & table.Tables(0).Rows(i)("z") & "','" & table.Tables(0).Rows(i)("c") & "','" & table.Tables(0).Rows(i)("FLG1") & "','" & newName & "')"
                    HandleMysql(InSql)
                Next
                table = SearchMysql(sql4)
                For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                    Dim InSql As String = "insert into pointpara(PointName,torque,angle,feeder,disable,ArchNO,GetPassNO,SetPassNO,Product,Way,High,X轴角度,Y轴角度) values('" & table.Tables(0).Rows(i)("PointName") & "','" & table.Tables(0).Rows(i)("torque") & "','" & table.Tables(0).Rows(i)("angle") & "','" & table.Tables(0).Rows(i)("feeder") & "','" & table.Tables(0).Rows(i)("disable") & "','" & table.Tables(0).Rows(i)("ArchNO") & "','" & table.Tables(0).Rows(i)("GetPassNO") & "','" & table.Tables(0).Rows(i)("SetPassNO") & "','" & newName & "','" & table.Tables(0).Rows(i)("Way") & "','" & table.Tables(0).Rows(i)("High") & "','" & table.Tables(0).Rows(i)("X轴角度") & "','" & table.Tables(0).Rows(i)("Y轴角度") & "')"
                    HandleMysql(InSql)
                Next
                'table = SearchMysql(sql5)
                'For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                '    Dim InSql As String = "insert into pointway(PointName,Way,High,X轴角度,Y轴角度,Product) values('" & table.Tables(0).Rows(i)("PointName") & "','" & table.Tables(0).Rows(i)("Way") & "','" & table.Tables(0).Rows(i)("High") & "','" & table.Tables(0).Rows(i)("X轴角度") & "','" & table.Tables(0).Rows(i)("Y轴角度") & "','" & newName & "')"
                '    HandleMysql(InSql)
                'Next
                table = SearchMysql(sql6)
                For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                    Dim InSql As String = "insert into robot_point(PointName,x,y,z,c,FLG1,Product) values('" & table.Tables(0).Rows(i)("PointName") & "','" & table.Tables(0).Rows(i)("x") & "','" & table.Tables(0).Rows(i)("y") & "','" & table.Tables(0).Rows(i)("z") & "','" & table.Tables(0).Rows(i)("c") & "','" & table.Tables(0).Rows(i)("FLG1") & "','" & newName & "')"
                    HandleMysql(InSql)
                Next
                table = SearchMysql(sql7)
                For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                    Dim InSql As String = "insert into timerdelay(TimerNO,TimeSet,Product) values('" & table.Tables(0).Rows(i)("TimerNO") & "','" & table.Tables(0).Rows(i)("TimeSet") & "','" & newName & "')"
                    HandleMysql(InSql)
                Next
            Else
                Dim sql As String = "select * from archpara where Product='" & oldName & "'"
                Dim sql1 As String = "select * from cad_point where Product='" & oldName & "'"
                Dim sql2 As String = "select * from passset where Product='" & oldName & "'"
                Dim sql3 As String = "select * from photo_point where Product='" & oldName & "'"
                Dim sql4 As String = "select * from pointpara where Product='" & oldName & "'"
                'Dim sql5 As String = "select * from pointway where Product='" & oldName & "'"
                Dim sql6 As String = "select * from robot_point where Product='" & oldName & "'"
                Dim sql7 As String = "select * from timerdelay where Product='" & oldName & "'"
                Dim table As DataSet = SearchMysql(sql)
                For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                    Dim InSql As String = "update archpara set UpMove='" & table.Tables(0).Rows(i)("UpMove") & "',DownMove='" & table.Tables(0).Rows(i)("DownMove") & "',UpPass='" & table.Tables(0).Rows(i)("UpPass") & "',DownPass='" & table.Tables(0).Rows(i)("DownPass") & "' where ArchNO='" & table.Tables(0).Rows(i)("ArchNO") & "' and product='" & newName & "'"
                    HandleMysql(InSql)
                Next
                table = SearchMysql(sql1)
                For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                    Dim InSql As String = "update cad_point set x='" & table.Tables(0).Rows(i)("x") & "',y='" & table.Tables(0).Rows(i)("y") & "',z='" & table.Tables(0).Rows(i)("z") & "',c='" & table.Tables(0).Rows(i)("c") & "',FLG1='" & table.Tables(0).Rows(i)("FLG1") & "' where PointName='" & table.Tables(0).Rows(i)("PointName") & "' and Product='" & newName & "'"
                    HandleMysql(InSql)
                Next
                table = SearchMysql(sql2)
                For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                    Dim InSql As String = "update passset set x='" & table.Tables(0).Rows(i)("x") & "',y='" & table.Tables(0).Rows(i)("y") & "',z='" & table.Tables(0).Rows(i)("z") & "',c='" & table.Tables(0).Rows(i)("c") & "' where PassName='" & table.Tables(0).Rows(i)("PassName") & "' and Product='" & newName & "'"
                    HandleMysql(InSql)
                Next
                table = SearchMysql(sql3)
                For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                    Dim InSql As String = "update photo_point set x='" & table.Tables(0).Rows(i)("x") & "',y='" & table.Tables(0).Rows(i)("y") & "',z='" & table.Tables(0).Rows(i)("z") & "',c='" & table.Tables(0).Rows(i)("c") & "',FLG1='" & table.Tables(0).Rows(i)("FLG1") & "' where PointName='" & table.Tables(0).Rows(i)("PointName") & "' and Product='" & newName & "'"
                    HandleMysql(InSql)
                Next
                table = SearchMysql(sql4)
                For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                    Dim InSql As String = "update pointpara set torque='" & table.Tables(0).Rows(i)("torque") & "',angle='" & table.Tables(0).Rows(i)("angle") & "',feeder='" & table.Tables(0).Rows(i)("feeder") & "',disable='" & table.Tables(0).Rows(i)("disable") & "',ArchNO='" & table.Tables(0).Rows(i)("ArchNO") & "',GetPassNO='" & table.Tables(0).Rows(i)("GetPassNO") & "',SetPassNO='" & table.Tables(0).Rows(i)("SetPassNO") & "' where PointName='" & table.Tables(0).Rows(i)("PointName") & "' and Product='" & newName & "'"
                    HandleMysql(InSql)
                Next
                'table = SearchMysql(sql5)
                'For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                '    Dim InSql As String = "update pointway set Way='" & table.Tables(0).Rows(i)("Way") & "',High='" & table.Tables(0).Rows(i)("High") & "',X轴角度='" & table.Tables(0).Rows(i)("X轴角度") & "',Y轴角度='" & table.Tables(0).Rows(i)("Y轴角度") & "' where PointName='" & table.Tables(0).Rows(i)("PointName") & "' and Product=" & newName & "'"
                '    HandleMysql(InSql)
                'Next
                table = SearchMysql(sql6)
                For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                    Dim InSql As String = "update robot_point set x='" & table.Tables(0).Rows(i)("x") & "'y=,'" & table.Tables(0).Rows(i)("y") & "',z='" & table.Tables(0).Rows(i)("z") & "',c='" & table.Tables(0).Rows(i)("c") & "',FLG1='" & table.Tables(0).Rows(i)("FLG1") & "' where PointName='" & table.Tables(0).Rows(i)("PointName") & "' and Product='" & newName & "'"
                    HandleMysql(InSql)
                Next
                table = SearchMysql(sql7)
                For i As Integer = 0 To table.Tables(0).Rows.Count - 1
                    Dim InSql As String = "update timerdelay set TimeSet='" & table.Tables(0).Rows(i)("TimeSet") & "' where TimerNO='" & table.Tables(0).Rows(i)("TimerNO") & "' and Product='" & newName & "'"
                    HandleMysql(InSql)
                Next
            End If
        Catch ex As Exception
            MsgBox("CopyMysql:" & ex.Message.ToString)
        End Try
    End Sub

    Public Sub DeleteMysql(ByVal oldName As String)
        Try
            Dim sql As String = "delete from archpara where Product ='" & oldName & "'"
            HandleMysql(sql)
            sql = "delete from cad_point where Product ='" & oldName & "'"
            HandleMysql(sql)
            sql = "delete from passset where Product ='" & oldName & "'"
            HandleMysql(sql)
            sql = "delete from photo_point where Product ='" & oldName & "'"
            HandleMysql(sql)
            sql = "delete from pointpara where Product ='" & oldName & "'"
            HandleMysql(sql)
            'sql = "delete from pointway where Product ='" & oldName & "'"
            'HandleMysql(sql)
            sql = "delete from robot_point where Product ='" & oldName & "'"
            HandleMysql(sql)
            sql = "delete from timerdelay where Product ='" & oldName & "'"
            HandleMysql(sql)
        Catch ex As Exception
            MsgBox("DeleteMysql:" & ex.Message.ToString)
        End Try
    End Sub

    Public Function SearchMysqlRemote(ByVal sql As String) As DataSet
        Dim str As String = "Server=" & MySQLIPRemote & ";User ID=" & MySQLUserNameRemote & ";Password=" & MySQLPassWordRemote & ";Database=" & MySQLDataBaseRemote & ";CharSet=utf8;pooling=true;Allow Zero Datetime=true"
        Dim con As New MySqlConnection(str)
        Try
            con.Open()
            Dim cmd As New MySqlCommand(sql, con)
            Dim ada As New MySqlDataAdapter(cmd)
            Dim ds As New DataSet()
            ada.Fill(ds)
            con.Close()
            Return ds
        Catch ex As Exception
            con.Close()
            MessageBox.Show("SearchMysqlRemote:" & ex.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return Nothing
        End Try
    End Function

    '对mysql进行增删改操作
    Public Function HandleMysqlRemote(ByVal sql As String) As Integer
        Dim str As String = "Server=" & MySQLIPRemote & ";User ID=" & MySQLUserNameRemote & ";Password=" & MySQLPassWordRemote & ";Database=" & MySQLDataBaseRemote & ";CharSet=utf8;pooling=true;Allow Zero Datetime=true"
        Dim con As New MySqlConnection(str)
        Try
            con.Open()
            Dim cmd As New MySqlCommand(sql, con)
            Dim i As Integer = cmd.ExecuteNonQuery()
            con.Close()
            Return i
        Catch ex As Exception
            con.Close()
            MessageBox.Show("HandleMysqlRemote:" & ex.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return 0
        End Try
    End Function

    ''' <summary>
    ''' 获取json字符串内容
    ''' </summary>
    ''' <param name="jkey"></param>
    ''' <param name="sourceStr"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getJsonKeyValue(ByVal jkey As String, ByVal sourceStr As String) As String
        Dim returnVal As String = ""

        Try
            Dim stIndex, endIndex, len As Integer
            Dim findIndex As Integer
            '"key":"VAL", "key":null,"key":123, "key":false
            findIndex = sourceStr.IndexOf("""" & jkey & """:")
            If findIndex < 0 Then
                Return returnVal
            End If
            stIndex = findIndex + jkey.Length + 3
            Dim endstr As String = """"
            Dim findEnd As Boolean = False '正常结束
            If sourceStr(stIndex) = """" Then
                '字符串
                stIndex += 1
                Dim flag As Boolean = False

                For i As Integer = stIndex To sourceStr.Length - 1
                    If flag = False Then
                        If sourceStr(i) = """" Then
                            flag = True
                            endIndex = i
                        End If
                    Else
                        If sourceStr(i) = """" Then
                            flag = True
                            endIndex = i
                        End If
                        If sourceStr(i) = "," Or sourceStr(i) = "}" Then
                            findEnd = True
                            Exit For
                        End If
                    End If
                Next
            Else
                '非字符串
                Dim flag As Boolean = False
                For i As Integer = stIndex To sourceStr.Length - 1
                    If sourceStr(i) = "," Or sourceStr(i) = "}" Then
                        endIndex = i
                        findEnd = True
                        Exit For
                    End If
                Next
            End If
            If findEnd = True Then
                len = endIndex - stIndex
                returnVal = sourceStr.Substring(stIndex, len)
            End If
        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
        End Try
        Return returnVal
    End Function

End Module